package sk.fiit.lulco.grafy;

import jargs.gnu.CmdLineParser;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;

import sk.fiit.lulco.gui.GraphItem;

public class Test {

	private static void printUsage() {
		System.err.println("test printu :)");
	}
	
	/**
	 * @param args
	 * @throws IOException 
	 */
	public static void main(String[] args) throws IOException {
//		CmdLineParser parser = new CmdLineParser();
//		CmdLineParser.Option aaa = parser.addStringOption('a', "alg");	// algoritmus
//		CmdLineParser.Option bbb = parser.addStringOption('b', "bbb");
//		CmdLineParser.Option ccc = parser.addStringOption('c', "ccc");
//		CmdLineParser.Option ddd = parser.addStringOption('d', "ddd");
//		CmdLineParser.Option rounds = parser.addStringOption('d', "rrr");	// pocet behov
//		
//		try {
//			parser.parse(args);
//		} catch (CmdLineParser.OptionException e) {
//			System.err.println(e.getMessage());
//            printUsage();
//            System.exit(2);
//		}
//		
//		System.out.println(parser.getOptionValue(aaa));

		File file = new File("./files/");
		File files[];
		files = file.listFiles();
		for (File f : files) {
			String filename = f.toString();
			if (filename.equals(".\\files\\.svn")) {
				continue;
			}
			//filename = ".\\files\\queen7_7.col";
			System.out.println(filename);
			
			if (filename.substring(0, 13).equals(".\\files\\le450")) {
				for (int i = 0; i < 5; i++) {
					Graph graph = new Graph(filename);
					System.out.println(i);
					//MyPageRankAlgorithm algorithm = new MyPageRankAlgorithm();
					//NewAlgorithm algorithm = new NewAlgorithm();
					//BrelazAlgorithm algorithm = new BrelazAlgorithm();
					//HEALAlgorighm algorithm = new HEALAlgorighm();
					NewHEALAlgorithm algorithm = new NewHEALAlgorithm(new GraphItem(filename, "", 0, 0));
					graph = algorithm.runPerformed(graph);
//					if (1 == 1) {
//						return;
//					}
					if (graph.isWellColored()) {
						try {
							BufferedWriter writer = new BufferedWriter(new FileWriter("log.txt", true));
							writer.write(filename + " - " + graph.getColors(null).size() + "\n");
							writer.write(graph.getFitness() + "\n");
							for (Vertex vertex : graph.getVertices()) {
								writer.write(vertex.getId() + ": " + vertex.getColor() + "\n");
							}
							writer.write("\n\n");
							writer.close();
							
							BufferedWriter updater = new BufferedWriter(new FileWriter(filename, true));
							updater.write("b " + graph.getColors(null).size() + " " + algorithm.getClass().toString() + "\n");
							updater.close();
	//						if (1 == 1) {
	//							return;
	//						}
						} catch (IOException e) {
							e.printStackTrace();
						}
					} else {
						System.out.println(filename + " je zle ofarbeny");
					}
				}
//				if (1 == 1) {
//					return;
//				}
			}
		}
		System.out.println("done");
//		for (Vertex vertex : graph.getVertices()) {
//			System.out.println(vertex.getId() + ": " + vertex.getColor());
//		}
		
	}
}